/**
 ********************************************************************
 * @author roocket
 * @file    dispenser.h
 * @version V0.0.0
 * @date    2024/3/22
 * @brief   This file is to indicate dispenser functions. 
 * @attention Code file rules:
 * rule: file encoding use UTF8;
 * rule: max line length 120 characters;
 * rule: line separator \r\n;
 * rule: use clion auto code format tool.
 */
#ifndef _DISPENSER_H_
#define _DISPENSER_H_

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <string.h>
#include <pthread.h>

#define DISPENSER_MAX_BUFFER_LEN 4096

#define DISPENSER_SHMT_LOCATION "/home/roocket/roocket_linux/app/dispenser/shmt"
#define DISPENSER_SHMT_MALLOC_BUFFER 128

struct dispenser_data {
    int length;
    char buffer[DISPENSER_MAX_BUFFER_LEN];
};

struct dispenser_config {
    int shmt_id;
    int shmt_size;
    struct dispenser_data *dip_data; 
    pthread_mutex_t rw_lock;
};

int dispenser_shmt_init(struct dispenser_config *dip_cfg);

void dispenser_shmt_del(struct dispenser_config *dip_cfg);

int dispenser_set_data(struct dispenser_config *dip_cfg, void *_from_user);

int dispenser_get_data(struct dispenser_config *dip_cfg, void *_to_user);

#endif /* _DISPENSER_H_ */
